package com.namlh.jpa.crud.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "USERS")//, uniqueConstraints = @UniqueConstraint(columnNames = "Email"))
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "UserId")
	private String userId;

	@ManyToMany(cascade = CascadeType.ALL)
	@JoinTable(name = "USERROLES", joinColumns = {@JoinColumn(name = "UserId")}, 
									inverseJoinColumns = {@JoinColumn(name = "RoleId")})
	private Collection<Role> roles;

	//@NotNull
	@Column(name = "UserName")
	//@Size(min = 1, max = 25)
	//@Pattern(regexp = "[A-Za-z0-9 ]*", message = "must contain only letters spaces and number")
	private String userName;

	@Column(name = "Password")
	private String password;

	//@NotNull
	@Column(name = "DisplayName")
	//@NotEmpty(message = "Display name cannot be empty")
	private String displayName;

	@Column(name = "FirstName")
	private String firstName;

	@Column(name = "Surname")
	private String surname;

	@NotNull
	@Column(name = "Email")
	//@NotEmpty(message = "Email address cannot be empty")
	//@Email(message = "Invalid email address, e.g. valid email address: example@gmail.com")
	private String email;

	@NotNull
	//@Size(min = 10, max = 12)
	//@Digits(fraction = 0, integer = 12, message = "Incorrect Format, valid e.g. 121212121212")
	@Column(name = "PhoneNumber")
	private String phoneNumber;

	@Column(name = "CreatedBy")
	private String createdBy;

	@Column(name = "CreatedDate")
	private Timestamp createdDate;

	@Column(name = "ModifiedBy")
	private String modifiedBy;

	@Column(name = "ModifiedDate")
	private Timestamp modifiedDate;

	@Column(name = "StartDate")
	private Timestamp startDate;

	@Column(name = "EndDate")
	private Timestamp endDate;

	@Column(name = "Status")
	private String status;
	
	public User() {}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Collection<Role> getRoles() {
		return roles;
	}

	public void setRoles(Collection<Role> roles) {
		this.roles = roles;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	public Timestamp getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Timestamp createdDate) {
		this.createdDate = createdDate;
	}

	public String getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public Timestamp getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Timestamp modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public Timestamp getStartDate() {
		return startDate;
	}

	public void setStartDate(Timestamp startDate) {
		this.startDate = startDate;
	}

	public Timestamp getEndDate() {
		return endDate;
	}

	public void setEndDate(Timestamp endDate) {
		this.endDate = endDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

}